package com.qfedu.mes.exception;

import com.qfedu.mes.common.CommonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CommonException.class)
    public CommonResult commonExceptionHandler(CommonException e) {
        // 一般异常信息需要存入日志系统
        System.out.println(e.getMsg());
        e.printStackTrace();
        return CommonResult.error(e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public CommonResult exceptionHandler(Exception e) {
        // 一般异常信息需要存入日志系统
        System.out.println(e.getMessage());
        e.printStackTrace();
        return CommonResult.error("未知异常，请联系客服");
    }
}
